﻿<!--#include file="Inc/easp/easp.asp"-->
<!--#include file="Inc/Conn.asp"-->
<!--#include file="Inc/easyide.asp"-->
<%
dim sql,rs
dim username,password,CheckCode
dim FoundErr,ErrMsg,RndPassword
username = replace(trim(request("UserName")),"'","")
password = replace(trim(Request("Password")),"'","")

if IsEmpty(Session("Passed")) then
	Session("Passed") = false
end if

if UserName="" then
	FoundErr = True
	ErrMsg = ErrMsg & "<br><li>User name can't for empty!</li>"
end if
if Password = "" then
	FoundErr = True
	ErrMsg = ErrMsg & "<br><li>Password can't for empty!</li>"
end if

if FoundErr <> True Then   
	set rs = Easp.db.GetRecordDetail("user", array("Name:" & username, "PassWord:" & password))
	
  If Easp.IsN(rs) then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>User name or password was error!</li>"
	else
		Session("Passed") = True
		Session("ID") = rs("ID")
		Session("GID") = rs("g_id")
		Session("Name") = rs("Name")
		Session("Password") = rs("Password")
		Session("Authority") = rs("Authority")

		Easp.db.C(rs)'关闭

		Response.Redirect "main.asp"	
	end if
	
    Easp.db.C(rs)
end If

if FoundErr=True then
	call WriteErrMsg()
end if

'****************************************************
'过程名：WriteErrMsg
'? 用：显示错误提示信息
'? 数：?
'****************************************************
sub WriteErrMsg()
	dim strErr
	strErr=strErr & "<html><head><title>Error Messages</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbcrlf
	strErr=strErr & "<link href='style.css' rel='stylesheet' type='text/css'></head><body>" & vbcrlf
	strErr=strErr & "<table cellpadding=2 cellspacing=1 border=0 width=400 class='border' align=center>" & vbcrlf
	strErr=strErr & "  <tr align='center'><td height='22' class='title'><strong>Error Messages</strong></td></tr>" & vbcrlf
	strErr=strErr & "  <tr><td height='100' class='tdbg' valign='top'><b>Error reason may be:</b><br>" & errmsg &"</td></tr>" & vbcrlf
	strErr=strErr & "  <tr align='center'><td class='tdbg'><a href='index.asp'>&lt;&lt; Returns the login page</a></td></tr>" & vbcrlf
	strErr=strErr & "</table>" & vbcrlf
	strErr=strErr & "</body></html>" & vbcrlf
	response.write strErr
end sub

Function GetRndPassword(PasswordLen)
	Dim Ran,i,strPassword
	strPassword=""
	For i=1 To PasswordLen
		Randomize
		Ran = CInt(Rnd * 2)
		Randomize
		If Ran = 0 Then
			Ran = CInt(Rnd * 25) + 97
			strPassword =strPassword & UCase(Chr(Ran))
		ElseIf Ran = 1 Then
			Ran = CInt(Rnd * 9)
			strPassword = strPassword & Ran
		ElseIf Ran = 2 Then
			Ran = CInt(Rnd * 25) + 97
			strPassword =strPassword & Chr(Ran)
		End If
	Next
	GetRndPassword=strPassword
End Function
%>